home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Utilities / Programming / CTools 2.2.1d / CTools™.help.text < prev   
Encoding:
Text File  |  1995-12-01  |  54.1 KB  |  1,481 lines  |  [TEXT/R*ch]

  1. CTools™
  2. A collection of C source file utilities.
  3.  
  4. An itty bitty bytes™ production.
  5.  
  6. Version 2.2.1d
  7.  
  8. ©Copyright 1995 by Kenneth A. Long,
  9.  
  10. CTools™ was originally written by Graham Haddock.
  11.  
  12.  
  13. Current Status
  14.  
  15. CTools™ was turned over to me by the author, Graham Haddock, who
  16. has no time for further development or support.  
  17.  
  18. Address any bug reports, wish lists, suggestions, recommendations,
  19. etc., to me, at:
  20.  
  21. kenlong@netcom.com
  22.  
  23.  
  24. CTools™ Functions:
  25. ------------------
  26. The CTools™ program is a collection of C text file tools and
  27. utilities that are useful for formatting and reading C source
  28. files, particularly some of the "stuff" that you obtain from
  29. downloaded sources.  These tools and utilities have been wrapped
  30. inside a Macintosh™ shell that includes a rudimentary editor
  31. function.  The editor is not intended for major programming
  32. activities, but it is useful for viewing and making preliminary
  33. modifications to files.
  34.  
  35.  
  36. • C Source Formatter 
  37. --------------------
  38. A  "C" Source Formatter or "Pretty Printer" which operates on
  39. files.  This utility will operate on any file which ends in the
  40. suffix ".c".  It will re-indent a file according to the nesting
  41. level of the segments of the program.  Multiple statements per
  42. line will be reformatted to have one statement per line.  The
  43. logic flow of a program (as viewed by a C compiler) should not be
  44. disturbed, but you will generally find the program much easier to
  45. read if it was not originally indented according to nesting
  46. levels.
  47.  
  48. It adds an extra carriage, return after brace level returns to
  49. zero, so that it will clean up a preprocessed file better.
  50.  
  51.  
  52. • C Flow 
  53. --------
  54. Abstracts C function calls and declarations from a C source file
  55. and produces a listing of the program's calling hierarchy.  This
  56. utility will operate on any file which ends in the suffix ".c". 
  57. It will generate a new  file with the original file name plus the
  58. suffix ".flw" which contains a  sequential indented list of all
  59. functions called from each function declaration.
  60.  
  61. It is a useful utility for understanding the overall flow and
  62. calling structure of a program, particularly one that has
  63. insufficient or no documentation or commenting.
  64.  
  65.  
  66.  • C Check
  67. ----------
  68. A program to find and report all badly matched openers and closers
  69. plus assignment/equality confusions in a C source file.  This
  70. utility will operate on any file which ends in the suffix ".c". 
  71. It will generate a new file with the original file name plus the
  72. suffix ".check" which contains the output comments from the
  73. utility.  It specifically comments on unbalanced openings and
  74. closings of brackets, braces, etc., and specifically looks for the
  75. use of "=" rather than "==" inside decision statements.  If the
  76. "Verbose" option is selected, the utility will comment on the
  77. placement of opening and closing braces which are not vertically
  78. aligned in the source code.
  79.  
  80.  
  81. • Cross Reference 
  82. -----------------
  83. This is a concordance or cross-reference utility for 'C' programs.
  84.  This utility will operate on any file which ends in the suffix
  85. ".c".  It will generate a new file with the original file name
  86. plus the suffix ".xref" which contains the cross referenced output
  87. from the utility.  It will generate a list of all variable and
  88. function names in the source code, along with the line number in
  89. which they appear.  In accordance with the operation of Think C™,
  90. this program does not recognise nested comments, but  it will
  91. properly deal with comments or quoted items which are inside
  92. single or double quotes.
  93.  
  94. Options support the following features:
  95.    - Cross-referencing of Think C™ reserved words.
  96.    - Generation of line numbered listing only.
  97.    - Generation of cross-reference only.
  98.  
  99.  
  100. • Strip File 
  101. ------------
  102. This tool is useful for cleaning up and converting files that you
  103. have imported from other sources such as IBM-PC based files, or
  104. Unix systems.
  105.  
  106. Text files obtained from IBM-PC based sources as viewed on a
  107. Macintosh usually have a row of "boxes" down the left edge of the
  108. screen, and a horizontal row of boxes at the bottom of the file. 
  109. These are actually control characters which are present in the
  110. file, but are not used by the Macintosh.  To convert and clean up
  111. this kind of file, just click "OK" at the Stripper dialog, which
  112. will remove all control characters not used by a Macintosh™ text
  113. file, as well as any characters with values above (hex)7F.
  114.  
  115. If the file does not appear to have any carriage returns, and the
  116. file just goes on to the right forever, then the file is probably
  117. a Unix type file, and the additional "Convert Unix File" option
  118. should also be checked.  Unix type text files use "LineFeed" ($0A)
  119. rather than "CarriageReturn" ($0D) as the Mac does to mark a new
  120. line.  The "Convert Unix File" option will substitute a
  121. CarriageReturn for each LineFeed before stripping.  If you check
  122. this box on an IBM-PC type file, then you will end up with
  123. everything double spaced, but no other harm done.
  124.  
  125. Although most Macintosh programs will not recognise them, there
  126. are some text editors like QUED which will respond to imbedded
  127. "Form Feeds" for page break control.  If these exist in the
  128. program, and you want to save them, activate the "Save FormFeed"
  129. option.
  130.  
  131.  
  132. • Pascal to C 
  133. -------------
  134. This utility will translate Pascal keywords and operators to their
  135. C equivalent.  This utility will operate on any files which DO NOT
  136. end in the suffix ".c".  It will generate a new file with the
  137. original file name plus the suffix ".p.c" which contains the
  138. translated output from the utility.
  139.  
  140. This program is an aid in translating a Pascal program to C.  It
  141. will do much of the repetitive mechanical conversion.  HOWEVER,
  142. the programmer will need a working knowledge of both Pascal and C
  143. to manually convert some Pascal features which this program cannot
  144. handle, or for which there is no direct C equivalent.
  145.  
  146.  
  147. • Prototype Generator 
  148. ---------------------
  149. This utility will generate C type prototypes from an (old style) C
  150. source file.   This tool has not been reworked to recognise ANSI
  151. style declarations yet.   This utility will operate on any file
  152. which ends in the suffix ".c".  It will generate a new file with
  153. the original file name plus the suffix ".pr" which contains the
  154. list of prototypes output by the utility.
  155.  
  156. (This one is almost useless.  How many old-style declarations do
  157. you write or run into?  I recommend the SUPERIOR prototype
  158. generator in CMaster™ from Jersey Scientific.)
  159.  
  160.  
  161. • Remove Tabs 
  162. -------------
  163.  This tool will convert all tabs to their equivalent number of
  164. spaces, according to the number of spaces selected in the "Tabs"
  165. menu.  The file may then be saved in this form, or it may then be
  166. re-Tabbed to a different tab setting, without disturbing the
  167. appearance of the file, by using the Re-Tab command below.  The
  168. program will also absorb any trailing tabs or spaces at the end of
  169. a line. 
  170.  
  171. As an example, if you have a Unix™ style file with Tabs st 8
  172. spaces that you wish to convert to 4 spaces, "Open" the file, and
  173. then select a setting in the "Tabs" menu that appears to provide
  174. the original appearance for the file.  Then run "De-Tab" to
  175. convert all tabs to spaces.  Now select 4 spaces per tab in the
  176. "Tabs" menu, and run "Re-Tab".  The appearance of any tables or
  177. comment headers will now be preserved, while you are now free to
  178. run the "C Source Formatter" on the source code.
  179.  
  180.  
  181. • ReTab 
  182. -------
  183. This tool will convert any spaces (which are not inside " or '
  184. quotes) into tabs according to the number of spaces per tab
  185. selected in the "Tabs" menu.  Spaces inside " or ' quotes are
  186. preserved.  The program will also absorb any trailing tabs or
  187. spaces at the end of a line.  It is not necessary to run "De-Tab"
  188. first, if you just want to clean up a file with the same Tab
  189. setting, where spaces and tabs were used interchangeably.
  190.  
  191. New In
  192. CTools™ version 2.2d:
  193. ---------------------
  194. • Added this help module (but it's slightly buggy).
  195. • Added Pascal to C comment style preferences.
  196. • Pascal to C now creates #define for *plain* constants! (It’s a
  197. start.)
  198. • Pascal to C now handles *plain* 'for' statements!  (It’s a
  199. start.)
  200. • Pascal to C typedef and record conversion improved!
  201. • Dropped formatter adding of spaces before certain left
  202. parenthesis.
  203.  
  204.  
  205. Improvements Since
  206. CTools™ version 2.16:
  207. ---------------------
  208. The jump from 2.16 to 2.2 was all on unreleased versions.  I
  209. decided to start with the next highest, relatively even, version
  210. number, for this release.
  211.  
  212. Pascal to C improvements:
  213. • Fixed it to handle many, many more character case discrepancies
  214. than before, on commonly encountered keywords.
  215. • Added translate table entries to add left and right parens after
  216. many common toolbox calls having no arguments.
  217. (i.e. InitWindows; to InitWindows ();).
  218. • Added translations for some minor, yet omitted, keywords and
  219. other things. (see Appendix)
  220. • Patched some small translation items resulting in less (or
  221. easier to do) manual editing.
  222. • Translate table additions: 135.
  223. • Added conversion for Pascal’s ‘@’ operator to C’s ‘&’ operator.
  224.  
  225. Other Improvements:
  226. • Made CTools™ save ‘TEXT’ files with its own signature, ‘GH22’
  227. for quick spotting in the Finder and SFGet dialog.
  228. • Gave CTools™ a new color icon.
  229. • Added color animated cursor during long processes.
  230. • Added "Select All" to the Edit Menu.
  231. • Added command key modifiers to the CTools™ menu items.
  232.  
  233. To Do List:
  234. - Make it handle ‘for’ loops.
  235. - Make it handle switches more completely.
  236. - Make it do constants better.    √ done (95%)
  237. - Improve typedef and record conversion.     √ done
  238. - Add ‘()’ after argumentless routine calls.
  239. - Make comment styles selectable.    √ done
  240. - Make source formatter configurable.
  241. - Correct left off paren on do-while loop.
  242. - Fix start brace dislocation in procedure parsing routine.
  243. - Fix missing ‘;’ on line before before ‘else’.
  244. - Put in more ‘&’ where needed.
  245. - Make Proto Gen work right for new and old style, so it’s more
  246. usable.
  247.  
  248. ...eventually...
  249. - Do C to Pascal.
  250. - Do batch translating.
  251. - Do flow of whole program
  252. (That oughta keep me busy!)
  253.  
  254.  
  255. Using CTools™
  256. -------------
  257. The primary caution to be considered is memory.  CTools™ can
  258. handle fairly big files, but has its limits.  If you do a big
  259. operation, don’t expect to b able to do another big operation
  260. without saving.  For example, if yo do Pascal to C on a file, then
  261. Source Code Formatter, it will crash.  If you do Pascal to C on
  262. the same file (after you restart), then save, THEN do Source
  263. Fomatter, it will probably not crash (didn’t for me).  See?
  264.  
  265. ------------------------------------------------------------------
  266.  
  267. C Source Formatter:
  268. -------------------
  269. The CTools™ C source formatter works beautifully.  It only works
  270. on files suffixed in ".c" though.  
  271.  
  272. The C source formatter will operate on a "Command 1" key
  273. combination on the open file, whereupon it does it and replaces
  274. the ext in the file with the formatted text.  If you want to keep
  275. this, then close and save, or vice versa.  Otherwise you MUST
  276. select "Save As" from the file menu if you do not want your
  277. original source altered.
  278.  
  279. I have never had an error in its output as long as the input was
  280. compilable code and not too big.  Sometimes it will balk on a
  281. BIG file, or one with some unusual weirdnesses.  But that’s very
  282. rare.  If it does do this, it will merely crash without eating
  283. your file (hopefully).  What I do, when I KNOW I have too big a
  284. file to format, is split it up.  Open the CTools™ "WorkSheet.c"
  285. file, select half the file to be processed file, copy it, paste it
  286. into the worksheet, format it, select all, cut, save the
  287. worksheet, switch back to the intended file and paste and save. 
  288. Then select the other half.  You can do this between your editor
  289. and CTools™ or all in CTools™.
  290.  
  291. The formatter doubles as a "C check" function, in that if there is
  292. a missing brace or missing semicolon or missing paren, the Source
  293. Formatter output will have odd indents immediately afterward.  You
  294. can correct these glitches right in the CTools™ window.  Scroll
  295. down until the code looks oddly indented, find the omission, add
  296. it, and run the formatter again.
  297.  
  298. If you have a missing "case" keyword before a ‘:’ then CTools™
  299. will not indent that line, so those are easy to find.
  300.  
  301. You can also paste a routine into a new CTools™ document being
  302. used as a "worksheet" and format it, then cut or copy it out.  The
  303. file must be "saved" with the ".c" suffix in order for it to work.
  304.  But if you want to pump code and not deal with indents until you
  305. are done, then just have CTools™ running in MultiFinder and, when
  306. you’re done typing, select all and copy, paste into your CTools™
  307. "worksheet.c", hit Command 1, select all and cut again, save the
  308. worksheet.c file (save empty) and then paste your source back into
  309. your code file.
  310.  
  311. One tip on big files, suppose you have a huge routine and CTools™
  312. doesn’t have enough "poop" to process it?  Simply:
  313.  
  314. ( 1) Move the insertion point to the top of the file in your code
  315. editor.
  316. ( 2) Drag the scroll thimb halfway down.
  317. ( 3) Hold SHIFT and click near the left margin.
  318. ( 4) Command V.
  319. ( 5) Switch to the CTools™ Worksheet.c window.
  320. ( 6) Command 1.
  321. ( 7) Command A.
  322. ( 8) Command X.
  323. ( 9)Commad S.
  324. (10) Switch back to your editor.
  325. (11) Command V.  
  326.  
  327. Now, the tricky part...
  328.  
  329. You’ll want the remaining, unformatted source from the file to
  330. have the same indent as the part it goes under IF you are
  331. mid-routine.  If you format the remainder the way it is, missing
  332. begin braces will result in mismatched indents.  So, do this:
  333.  
  334. ( 1) Put the insertion point just before the first character of
  335. the last 
  336.         line of the code you just formatted.
  337. ( 2) Hit the left arrow and count how many times you hit it to get
  338. the
  339.         insertion point to the left margin.
  340. ( 3) Hit the down arrow to get below that code.
  341. ( 4) Drag the scroll thumb to the bottom of the file.
  342. ( 5) Hold Shift and click past the end of all the code.
  343. ( 6) Command C.
  344. ( 7) Switch back to the CTools™ Worksheet.c window.
  345. ( 8) Type the same number of begin braces as the number of left
  346. arrow hits 
  347.         you counted earlier.
  348. ( 9) Command V.
  349. (10) Command 1.
  350. (11) Command X.
  351. (12) Command S.
  352. (13) Switch back to your editor.
  353. (14) Command V.
  354.  
  355. I will be working in more user configurability but, until then,
  356. YOU have to do a little configuration on your own if you do not
  357. want your source to appear as CTools™ puts it out - but not much.
  358.  
  359. If a brace is on the same line as an 'if' statement it will stay
  360. there.  If you want it on its own, new line, pre-edit by using a
  361. Find/Replace function in a text editor.  Find " {" (space
  362. leftBrace) and Replace All with "<cr>{" (return leftBrace) before
  363. running the formatter.  A Find/Replace function will be added to
  364. CTools™, soon, so you can do this "in-house", but it will probably
  365. just be a part of the preferences.
  366.  
  367. If you want to see how good this formatter is, preprocess a small
  368. source file, replace all RETURNs with a space, save the result and
  369. run the formatter on it!  
  370.  
  371. If you intend to clean up CTools™ output from the Pascal to C
  372. function, you MUST edit it so that it has ALL matching braces,
  373. parens and semicolons first.  The technique for doing this is
  374. detailed in the Pascal to C section.
  375.  
  376. ------------------------------------------------------------------
  377.  
  378. Pascal to C:
  379. ------------
  380. Using the CTools™ Pascal to C function will save you a LOT of
  381. work!  The sequence for doing so with CTools™ has five basic
  382. steps:
  383.  
  384. (1) Get a complete rough C translation.
  385. (2) Get all routines to appear in a "function popup" menu.
  386.     (Good C source editors have function popups).
  387. (3) Get the file ready to clean up with the CTools™ C Source
  388. Formatter.
  389. (4) Get it to compile and link.
  390. (5) Get it to run.
  391.  
  392. Getting A Complete Translation
  393.  
  394. Sometimes CTools™ does not completely translate a file with the
  395. CTools™ Pascal to C function.  Errors in getting a complete output
  396. can be worked around.  If you run Pascal to C, scroll down the
  397. output window to the bottom.  If there are no translation errors
  398. you will see "}." there.  If not, there was an abnormal
  399. termination of the translation due to something CTools™ is not yet
  400. made able to handle.
  401.  
  402. Abnormal terminations are caused by:
  403. (1) More than 32 variables being assigned to one type declaration.
  404.     Solution:  Split them up.
  405. (2) An array declared with a byte range (i.e. "0..255"), including
  406. the
  407.         "packed" Pascal keyword.
  408.     Solution:  Change it before translating.
  409. (3) Any wrong Pascal source, such as seen in a "Rascal" file, such
  410. as void procedures which have parens, or some such.
  411.     Solution:  Correct them.
  412. (4) It seems to balk at the word "Implementation".
  413.     Solution: Comment it out.
  414.  
  415. If an abnormal termination has happened, simply:
  416.  
  417. (1 ) Note WHERE in the Pascal file the translation stopped.
  418. (2 ) CLOSE AND DO NOT SAVE the translation.
  419. (3 ) Scroll down the open, original Pascal window to that place.
  420. (4 ) Comment out or otherwise correct the erring line.
  421. (5 ) Attempt another complete translation.
  422. (6a) If complete, save and close the translation.
  423. (6b) If incomplete, repeat steps 2 through 6.
  424. (7 ) Close and do not save the original Pascal file.
  425.  
  426. Another form of incomplete translation, where it does not
  427. abnormally terminate, yet does not properly translate, are when
  428. the word "packed" is read in a type definition.
  429.  
  430. So, before you even try to translate the file, to save time and
  431. trouble, it would be wise to pre-edit the Pascal file (a copy) and
  432. remove all occurrences of the word "packed" and change any range
  433. variables to the Pascal version of what they will end up being
  434. (i.e. change "0..255" to "integer").
  435.  
  436. Multiple files:
  437. ---------------
  438. The best way to do a primary, rough translation on a multiple file
  439. program is to launch CTools™ and navigate, in the SFGetFile
  440. dialog, to the desired Pascal source file set folder, scroll to
  441. the bottom of the list, select the last file in the list and use
  442. my "KodeKeys" macro.  The macro is a sequence which opens the
  443. file, does Pascal to C and saves and closes the file, then looks
  444. for another one.
  445.  
  446. From then on, it’s just scroll, select, hit the hot-keys.  When
  447. you get done with the top one on the list, click Cancel.
  448.  
  449. Manually, once you navigate and select the bottom one on the list,
  450. translate it (making sure it’s complete), save, close, close,
  451. open, select the second to the last one, etc., etc., until you’ve
  452. rough translated them ALL.
  453.  
  454. The reason you start at the bottom of the list should be obvious. 
  455. If not, it’s because when you add translated files to the list *it
  456. grows*.  If you start at the top, clicks in the pageDown will
  457. become more numerous to get to the ones not yet done.  Start at
  458. the bottom and the navigation to the undone ones will be minimal.
  459.  
  460. Merge Them
  461. ----------
  462. If you are translating a complete Pascal program, consisting of
  463. multiple source and unit files, it is far better to edit ALL the
  464. files at once.  Chances are what produces a compiler error in one
  465. file will produce them in others.  It’s better to correct an error
  466. throughout the entire source/header area, than to set up
  467. "Find/Replace" several times, one file at a time
  468.  
  469. To do this, get a complete CTools™ output for ALL the files. 
  470. Units and .p files.  Pascal programs sometimes have a "Globals.p"
  471. file (with whatever actual name).  CTools™ will save it as
  472. "Globals.p.c" but it will eventually end up being the main header
  473. file, "Globals.h."  What you need to do is MERGE all files
  474. (kilobyte size permitting) and put all global data files at the
  475. top.  You can separate them back into .c files later, but for the
  476. purposes of manual editing, it is essential to have the least
  477. number of files (preferably one) as possible.
  478.  
  479. My Think C has been allocated with enough memory to easily handle
  480. a 300K merged file.  Set yours up to the maximum possible - within
  481. reason.
  482.  
  483. What I do is run all the files through CTools™ Pascal to C, then
  484. select all the output files destined to become headers and drop
  485. them on TextMerge by Robert Gibson.  This creates a new file
  486. called "Merged File 0" and consists of copies of the content of
  487. all the files in alpha. order (View by Name).  I do the same with
  488. what will become sources and it’s named "Merged File 1".  Then I
  489. drop both these on the merger and it outputs "Merged File 2" which
  490. I rename to Merged.c.
  491.  
  492. Your alphabetical order is changed by adding an ‘a’ prefix to some
  493. file names and a ‘z’ to others, prior to the merge.  Once merged,
  494. the Merged File 3 is renamed "Merge.c" (or the program name) for
  495. editing.  Dump the first merges, retaining only the rough
  496. translation files (put all their names back like they were) and
  497. Merge.c.
  498.  
  499. One advantage is you now have copies of your CTools™ output, in
  500. case you want to revert to, or refer to, any of it in editing the
  501. merged file.  But the main advantage is you only have to correct
  502. one thing ONCE instead of for each file.  And you do the
  503. correction for the whole program the FIRST time it is encountered.
  504.  
  505. Navigation from file to file without excessive scrolling is a snap
  506. with CMaster™ (or your "Command E" and then Command G without
  507. CMaster™) by selecting the word "translation" and using the
  508. up/down search arrows.  That’s a unique word in the merged file
  509. and appears at the top of EACH individual file which was merged.
  510.  
  511.  
  512. A little Pleasure Before the Pain...
  513. ------------------------------------
  514. At this point, once you get a completed file translation, whether
  515. single or multiple files, you may as well set up a project for the
  516. soon to be running C program.  Launch your environment, create a
  517. new project with the proper name, add all the libraries it will
  518. need, add all the CTools™ ouput files you just created, do what
  519. you need in order to get the resource file associated with the
  520. project.
  521.  
  522. Don’t be concerned, at this point, about the xxxx.p.c suffix on
  523. the file names, or the ‘GH22’ creator of them.  A later step will
  524. make those right.  Set the project preferences to be all "kosher"
  525. (clean, in order, right) for the new program.
  526.  
  527. If you will be editing with your environments editor, then you
  528. will likely not need to open any of the converted files you’ve
  529. added.  You’ll be concentrating on on getting the surrogate
  530. "Merged.c" to compile.
  531.  
  532.  
  533. Let the Pain Begin!
  534. -------------------
  535. It's time for manual editing!  Get the Preparation H restocked,
  536. put on the wrist straps, load up several coffee filters in
  537. advance, etc!  Here we go!
  538.  
  539. You’ll do the editing in your favorite code editor. I have
  540. developed several ways of making the manual editing go faster and
  541. easier.
  542.  
  543. Once you have translated the file, quit CTools™ and open the new
  544. .p.c file in your code editor.  Two things that will help here ,
  545. tremendously, is Think C with CMaster™ and QuicKeys™ (as
  546. mentioned).  Without these two things (or comparable utilities, if
  547. that's possible) the editing of CTools™ Pascal to C output can and
  548. will be a drudgery.  But, still, not as bad as a direct
  549. translation of a Pascal file (although I’ve got that down to a
  550. science, too)!
  551.  
  552. In addition to these two EXCELLENT utilities, adding in a
  553. "Command-equivalent" key for your "Replace All" menu item is
  554. essential!  I use the asterisk, because it’s right next to the
  555. mouse, on the numeric keypad.  You do NOT want to be making a
  556. mouse trip to the menu bar for the Replace All function!  You are
  557. going to be using it 100s of times in the coming task!
  558.  
  559. Use ResEdit or Commander, or whatever, but get a unique
  560. Command/equivalent modifier key for this menu item. (Make sure you
  561. use a unique key.)
  562.  
  563.  
  564. Function Pop-Up:
  565. ----------------
  566. The first goal in editing is to get all the routines to show up in
  567. the "Function Pop-Up" menu.  This is so you will know you’ve got
  568. whole routines to End Of File, and also for faster navigation.  If
  569. you don’t do this first, they will just be extra compiler errors
  570. later.
  571.  
  572. For all routines to so appear in the popup, there must be an equal
  573. number of start and end braces, and no "nested functions."
  574.  
  575. CTools™ only converts the "var" and first "begin" in place.  It
  576. eats "var" and changes "begin" into a begining brace.  Since
  577. Pascal is "backward", these begining braces are in the wrong place
  578. - after the variables.  This is relatively easy to remedy.
  579.  
  580. Find:
  581.  
  582. )<CR>   // (right paren, return)
  583.  
  584. and replace with:
  585.  
  586. )<CR>{  // (right paren, return, left brace)
  587.  
  588. Do this manually using Command G and/or Command H, so you can SEE
  589. what you are changing.  Automatic ("Replace All") will create the
  590. need for extra editing by doing it to ALL routines!  You don’t
  591. want to do it to routines - only prototypes.
  592.  
  593. Before dealing with the, now, extra brace, you MUST replace the:
  594.  
  595. };
  596.  
  597. with:
  598.  
  599. }
  600.  
  601. You can use the Replace All command for this one.  This is done to
  602. prevent interference with the next two editing steps without
  603. eating your start braces on nested functions.
  604.  
  605. Still cleaning up the extra start braces, you’ll find two
  606. situations:
  607. (1) The extra begin brace is after a line ending in a comment.
  608. (2) The extra begin brace is after a line ending in ‘;’.
  609.  
  610. In either case, there may be one or more carriage returns, then
  611. one or more TABs, before the brace.  If there’s one RETURN and one
  612. TAB, Find:
  613.  
  614. ;
  615.     {    // (semicolon, return, tab, left brace)
  616.  
  617. and replace with:
  618.  
  619. ;
  620.        // (semicolon, return)
  621.  
  622. You may have to add TABs and RETURNs as needed, depending on the
  623. variety of indents and returns carried over from the Pascal.
  624.  
  625. On this last one, the only thing that will prevent you from
  626. getting them all is a comment after the ';' in the first line.  To
  627. find these, use the Function Pop Up.  The extra brace will be in
  628. the bottom one on the list or in the routine just below it.
  629.  
  630.  
  631. Nested Routines
  632. ---------------
  633. The only remaining preventer of all routines showing up in the
  634. popup are Pascals lovely "nested functions" thingy.  These are
  635. fairly easy to fix.  Sometimes they can be quite complex.
  636.  
  637. In the Function Pop Up, one of these will be the bottom routine on
  638. the list.  They are identified by a start brace but then a
  639. complete routine after the variables are declared.  Here’s an
  640. example from "Icosahedron":
  641.  
  642. In the Pascal to C output, it’s:
  643.  
  644. // The primary routine beginning.
  645. void Shadefaces()
  646. {                        // You have to add this brace.
  647.     short ThisFace;      // These variables...
  648.     RgnHandle aRegion;   // ...do not appear...
  649.     short Level;         // ...in the nested routine.
  650.  
  651.     // Nested routine begins here.
  652.     double Bright (Coordinates PlaneNorm, Coordinates LightNorm)
  653.     {
  654.         Bright = ((PlaneNorm[1] * LightNorm[1] +
  655.                    PlaneNorm[2] * LightNorm[2] + 
  656.                    PlaneNorm[3] * LightNorm[3]) + 1.0) / 2.0
  657.     }    // End of nested routine.
  658.  
  659. {    // Begin of primary routine.
  660.     aRegion = NewRgn();  // First used from primary variables.
  661.     for (ThisFace = 0; ThisFace < kNumFaces; ThisFace++)
  662.     {
  663.     [snip]
  664.         level = ceil(Bright(Normal, light) * 64.0);
  665.     [snip]
  666.     }
  667. }    //• Shadefaces.    // End of primary routine.
  668.  
  669. Select the part above the complete routine and copy it.  In
  670. CMaster™, hit your hot-keys (or tool icon) to comment this out.
  671.  
  672. // void Shadefaces()
  673. // {
  674. //     short ThisFace;      // These variables...
  675. //     RgnHandle aRegion;   // ...do not appear...
  676. //     short Level;         // ...in the nested routine.
  677.  
  678. Now, scroll down until you find the actual start of that copied
  679. routine declaration with variables.  There'll be a start brace
  680. right after an end brace.  Depending on how many functions are
  681. nested within it, the first one of these you find may or may not
  682. be where that goes.  Sometimes the author of the Pascal code marks
  683. it with a comment (hopefully).  Anyway, wherever you find it,
  684. select the start brace, hit RETURN and then paste the declaration
  685. and variables.
  686.  
  687. In our example, here’s what you end up with:
  688.  
  689. // UN-Nested routine begins here.
  690. double Bright (Coordinates PlaneNorm, Coordinates LightNorm)
  691. {
  692.     Bright = ((PlaneNorm[1] * LightNorm[1] +
  693.                PlaneNorm[2] * LightNorm[2] + 
  694.                PlaneNorm[3] * LightNorm[3]) + 1.0) / 2.0
  695. }    // End of nested routine.
  696.  
  697. (NOTE: The array element values are all 1 too high.)
  698.  
  699. // The primary routine beginning.
  700. void Shadefaces()
  701. {                        // You have to add this brace.
  702.     short ThisFace;      // These...
  703.     RgnHandle aRegion;   // ...do not appear...
  704.     short Level;         // ...in the nested routine.
  705.                          // Where original "begin" was.
  706.     aRegion = NewRgn();  // First used from primary variables.
  707.     for (ThisFace = 0; ThisFace < kNumFaces; ThisFace++)
  708.     {
  709.     [snip]
  710.         level = ceil(Bright(Normal, light) * 64.0);
  711.     [snip]
  712.     }
  713. }    //• Shadefaces.    // End of primary routine.
  714.  
  715. One way you can find them is to look in the variables in the
  716. "primary header declaration" (which you copied and commented out)
  717. and find the first occurrence of its use, following it.  There
  718. will often be one that is unique to the body of the routine where
  719. that declaration goes.  In the example, Bright did not contain
  720. ThisFace, aRegion or Level, so you can find the "nest" with those
  721. as search strings.  The next occurrence of one of these variables
  722. beyond its original location, where there’s a ‘}’ followed by a
  723. ‘{‘ just above it, will be where the primary function beginning
  724. goes.
  725.  
  726. If there are several nested routines, the first set of variables
  727. may belong to more than one of them.  You don’t need to be
  728. concerned about those until compile time.  A decision will have to
  729. be made whether to make several locals or all of those global, at
  730. that time.
  731.  
  732. Now check the Function Pop Up.
  733. ------------------------------
  734. So, you just repeat these steps until ALL routines show in the
  735. popup.  The last routine - main () - will not be declared.  You’ll
  736. have to type in the declaration yourself.  Pascal programmers
  737. usually mark this well.
  738.  
  739. The last brace of the program file (end of "main") has a dot after
  740. it which you may as well remove while you’re there.
  741.  
  742.  
  743. Cleaning It Up:
  744. ---------------
  745. Now that you’ve got the routines "popping up all over the place",
  746. you must handle any other things which will prevent CTools™ C
  747. Source Formatter from giving a clean output, which is the next
  748. goal of editing.  The reason you do this now is because it takes
  749. care of a few things which would become compiler errors, and it
  750. makes the C source (it’s not Pascal any more) easier to read and
  751. follow.
  752.  
  753. These preventers are:
  754.  
  755. (1) Last right paren (')') missing from the end of a do-while
  756. loop.
  757. (2) Improper or absent switch components (i.e. no "case " or
  758. "break;").
  759. (3) No end-of-line semicolon (;) before "else" keywords.
  760.  
  761. For the "do-while" in CMaster™, you simply find "while" and using
  762. the up/down selection search function to find them.  Start at the
  763. top of the file, click the down button, if it is a "while" at the
  764. end of a do/while loop, hit Command leftArrow, then rightArrow
  765. once and type a ')' there.  If there are comments on the line, you
  766. must manually place the insertion point.  Do this until EOF or it
  767. wraps back to the first one.  If you don’t have CMaster™ use
  768. Command G and the left/right arrows as above.
  769.  
  770. Improper switch components are no "case " before the cases, no
  771. "break;" between the cases commas where ":RETURNcase " should go. 
  772. If you have KodeKeys, you've been "saved" from a monotonous,
  773. drudgery.  Use my KodeKeys macro set for these (does one
  774. intermediate comma).
  775.  
  776. Use Find to find the first occurrence of the word "switch" in your
  777. CTools™ output.  In CMaster™, get that word into the selection
  778. search queue.  You can see that the word "case " is missing from
  779. the switch components.  Put them there.
  780.  
  781. With my macros, you simply put the insertion point before the
  782. first one and type "ctrl[3]" (control key, numeric pad 3).
  783.  
  784. Move down to where the next "case " goes, type "break;", hit
  785. RETURN twice and type "case " again.
  786.  
  787. With my KodeKeys macros, simply put the insertion point where
  788. "case " goes and type "ctrl-option-[3]" (control, option, numeric
  789. pad 3).  It's automagically and correctly updated.
  790.  
  791. If there are two case possibilities, with a comma, like:
  792.  
  793. keyDown, autoKey:
  794.  
  795. then hit "ctrl-shift-[3]" using the KodeKeys macros.  It will turn
  796. the above into:
  797.  
  798. break;
  799.  
  800. case keyDown:
  801. case autoKey:
  802.  
  803. in one shot!
  804.  
  805. Otherwise, just type in "case " and a space and replace the comma
  806. with a ':' and return and another "case" and space, so that it
  807. looks like the above example.
  808.  
  809. When you get down to the last one, you type "break" after it.  The
  810. macro for that is "ctrl[2]" alone.
  811.  
  812. It may be that break; does not belong there.  Maybe it has return,
  813. instead.  Determine this as you go.
  814.  
  815. Lastly, find all else with CMaster’s selection/search function and
  816. add a ‘;’ to the end of the previous code line (where they are
  817. missing).
  818.  
  819. Now, if you are in a big merged file, format the source later -
  820. after a complete compile and you’ve split the files back up into
  821. their individual .c files.  On a single file, run the CTools™ C
  822. Source Formatter now, to sort out the appearance.  This editing
  823. step will not make the source proper for the compiler, but will
  824. make it easier and ready to edit for compilation.
  825.  
  826. Be sure not to feed the formatter too big a chuck of code to
  827. format at one time.
  828.  
  829.  
  830. Compiling
  831. ---------
  832. Now that you’ve got all routines sorted out to pop up in the menu,
  833. and have all ‘;’ and  ‘)’ and ‘{‘ and switches taken care of, it’s
  834. time to get it to compile in C.  
  835.  
  836. In Think C, I use "Check Syntax" on the file, rather than "Run" or
  837. "Compile."  That way I don’t have to deal with the error window. 
  838. No need to try to compile or run when you KNOW it won’t do either,
  839. at this point!  The error window will only give you the first
  840. error anyway.
  841.  
  842. CTools™ only marks some things which the user may or may not want
  843. done a certain way.  The first of these is "Includes:" - the
  844. carry-over from Pascals "Uses" line.
  845.  
  846. My KodeKeys macros can help, here.  Hit ctrl-i for #include <.h>
  847. or ctrl-option-i for #include ".h", then just paste in the name of
  848. the header included.
  849.  
  850. Add the appropriate include directives and comment out or cut out
  851. the "dead" code.  Pascal includes (uses) some of its own source
  852. files.  C does not usually do this.  So, in the ".p" file, which
  853. once may have said "Uses MyMenus.p", it does not, now, need
  854. "#include "MyMenus.p.c".  Dig?  C only wants header data.  If
  855. there is "header stock" in the "MyMenus.p.c" file that IS needed
  856. by another c. file, then cut it and put it in a seperate header.
  857.  
  858. For the rest of the file, you may want to consult the Pascal
  859. original for comparisons - especially if an omission is suspected.
  860.  Also, compare forms of what’s translated to comparable things in
  861. working C sources.  From that, a good "source detective" should be
  862. able to get a correct translation where CTools™ falls down.
  863.  
  864.  
  865. Constants:
  866. ----------
  867. CTools™ now does constants fairly well!.  Yaaaay!  About 95% of
  868. them will require no further editing IF you want #defines.  The
  869. remaing 5% will be fixed.  Until then, you have to clean these up
  870. manually.  What I do is copy them all out to a new file where I
  871. can use Find/Replace without messing up something else, fix them
  872. all up fast and copy/paste them back.
  873.  
  874. Here’s an example of output which balked:
  875.  
  876. Pascal input:
  877. HOMEKEY = chr(1);
  878.  
  879. CTools™ output:
  880. #define HOMEKEY chr#define 1/***# Expected const identifier ***/
  881.  
  882. Correction:
  883.  
  884. Replace All "/***# Expected const identifier ***/" with a space
  885. and Find
  886. all the second "#define " using Command G/H and replace with a
  887. space, to get:
  888.  
  889. #define HOMEKEY chr 1    
  890.  
  891. See...  I only just got it to do constants into defines.  I need
  892. to add something to handle parens and such.
  893.  
  894. If the constant has more than a definition and a meaning, such as a
  895. plus or anything more than the two words (or #s), it will go out of
  896. synchronization.  The output can still be editied but not as easily
  897. as if the were merely commented out ahead of time.
  898. On a multi-file, use CTools™ "#define" keyword to navigate down
  899. the file, to get to where these incorrectly translated contants
  900. are.
  901.  
  902.  
  903. Typedefs:
  904. ---------
  905. Most typedefs will be usable, if you’ve pre-edited the range types
  906. and removed the "packed" keword.   If the Pascal range in an array
  907. was from zero, the translated one may be one short.  It used to
  908. automatically add "+1" to all of them.  I removed that as kludge,
  909. because the majority are translated correctly.  So watch for
  910. discrepancies.
  911.  
  912. Compare the "translation" to a working C source, and compare to
  913. the Pascal original, to make them complete and correct.  Or look
  914. at some typedefs in you Mac #includes headers, to see how they
  915. should be.
  916.  
  917.  
  918. From Then, On:
  919. --------------
  920. Once past the typedefs, the global variables will be mostly ready
  921. to go exactly as they are.  And the rest of the file will be
  922. relatively easy to edit.
  923.  
  924. If CTools™ hits a "Str4[4] name;" it will scramble it with a 
  925. previous type.  Just look at the Pascal file and see how it’s 
  926. supposed to be and fix it.  just find these ahead of thime and
  927. chanege them to Str255 or whatever.  (This is just another thing 
  928. on my list of things to correct - will  it ever end!).
  929.  
  930. The biggest "pest" of the editing process is screwed up character
  931. case.  It may say "itemHit" 20 times in the file, and one or two
  932. times it will say "ItemHit" or "itemhit" or even "ITEMHIT".  My
  933. KodeKeys macros handle this.  And, whenever you encounter ANYTHING
  934. that gives a compiler error, correct it for the rest of the file
  935. right then and there.
  936.  
  937. One important thing is, when you use Find/Replace, be SURE you
  938. evaluate whether to set "Ignore Case", "Wrap Around" and "Whole
  939. Words" FIRST.  The "Selection - Replace All" KodeKeys sequence I
  940. just mentioned MUST have "Whole Words" checked before using it. 
  941. Otherwise it will mess up some things.
  942.  
  943. Using Find/Replace for C source from a Pascal conversion is an
  944. art, to selectively edit the whole file precisely.
  945.  
  946. Sometimes you will fix something in the rest of the file and it
  947. will mess up something you already edited.  Should’ve had "Wrap
  948. Around" unchecked!  See?
  949.  
  950. The oddball character case boo-foos usually show up with the "xxxx
  951. has not been declared" compiler error, but you KNOW it has already
  952. been declared (the ONE exception to this is in a "with" block). 
  953. So, it was declared and used earlier, but with one or more
  954. characters in the wrong case.  I can correct this so it’s
  955. automatically handled.  Until then...  (ho hum)...
  956.  
  957. The quickest way to handle this is to get the one where you are
  958. like you want all of them to be, select it, copy it, and paste it
  959. in the Find dialog for both the search string and the replace-with
  960. string, and then Replace All (Whole Words checked).  Editing this
  961. one word for character case is made easy by having a macro in
  962. CMaster™ to invert case.  I do this with one key hit of the "back
  963. accent" key (upper left of keyboard).  I’ve never used that
  964. character for anything else, so I use it for that.  I hit it and
  965. the next character gets inverted, case-wise.  Or on a selection
  966. and the entire selectio inverts case.  EXCELLENT!  Handy!
  967.  
  968. For those of you using KodeKeys, simply edit the word to your
  969. liking (don’t add or subtract characters), select it, then hit
  970. ctrl-[0] (control, keypad 0) and the sequence will be executed. 
  971. It’s mega-fast and easy!  (Make sure "Whole Words" is checked
  972. before doing this.)
  973.  
  974.  
  975. "VAR" Left in Parameters
  976. ------------------------
  977. Sorry about this one, too (I didn’t write  the thing!).  These are
  978. handled easily, for the whole file, by setting up Find with "var "
  979. (var, space) and Replace With with nothing  and hitting Command G
  980. to find them individually.  When you find one leave it there, add
  981. the ‘*’ before the variable name it goes to and hit Command G
  982. again.  Do this from the top, until it wraps, and then Replace All
  983. by hitting your Command *.  Any other way is slower and more
  984. invloved.
  985.  
  986.  
  987. "WITH" Blocks
  988. -------------
  989. The *exception* to the undeclared variable name which you know has
  990. already been declared is in the "with" block and is easy to spot. 
  991. You get a compiler error saying "so-and-so has not been declared".
  992.  You suspect screwy character case.  With KodeKeys, you edit the
  993. offender and select it and hit "ctrl[0]" and all occurrences of it
  994. are changed to the upper/lower you just set.  Attempt a compile
  995. and still get the same error.  Look just above that for a "with"
  996. marker.  Here’s an example:
  997.  
  998.     //• WITH:  oldRect )    // CTools™ marker.
  999.     {
  1000.         SizeWindow(wPtr, right - left, bottom - top, false);
  1001.         ResizeText(good)        /* redraw text in wind**/
  1002.     ;}
  1003.  
  1004. The error was "right" has not been declared.  Well, you KNOW it
  1005. has been, in QuickDraw.h!  So the "with" is the culprit.  With
  1006. what?  Something goes WITH "right". "oldRect" goes with it!  So,
  1007. you put a dot after "oldRect", hold down SHIFT, click in front of
  1008. "oldRect." and copy to the clip.  Put the cursor in front of
  1009. "right" and paste.  Continue this for any other "undeclared" in
  1010. the "with" block (in this case identified by braces) and move on
  1011. to the next error.  The finished product will look like this:
  1012.  
  1013.     //• WITH:  oldRect. )// CTools™ marker.
  1014.     {
  1015.         SizeWindow(wPtr, oldRect.right  - oldRect.left, 
  1016.                          oldRect.bottom - oldRect.top, false);
  1017.         ResizeText(good);    /* redraw text in wind**/
  1018.     }
  1019.  
  1020. The braces delineating the "with" block should be left in, for the
  1021. time being.  Sometimes there are nested or double WITH blocks, and
  1022. these braces help reduce confusion.  Leave the  with marker in,
  1023. also.  You may have to come back and get information or do
  1024. something else.  Save removing this stuff until the final posh up,
  1025. after it runs.
  1026.  
  1027. Nested WITHs are handled similarly.  They will say:
  1028.  
  1029. //• with something, somethingElse )
  1030.  
  1031. or
  1032.  
  1033. //• with oneThing )
  1034. {
  1035.     SomeStuff (one, two, three);
  1036.     //• with anotherThing )
  1037.     {
  1038.         SomeMoreStuff (four, five, six);
  1039.         [on and on]
  1040.     }
  1041.     [blah, blah, blah]
  1042. }
  1043.  
  1044. It may be tricky figuring out what goes WITH what.  I recommend
  1045. getting a copy of Icosahedron.p and Icosahedron.c and comparing
  1046. them, if you run into a severe nested with block.  It has a LOT of
  1047. them and both programs run.
  1048.  
  1049. A hint as to what goes with what is in the type of variable the
  1050. names belong to, and what struct they are in.  The ones with
  1051. rectangle references for one "with" are fairly easy to figure out.
  1052.  
  1053.  
  1054. Missing Parenthesis’
  1055. --------------------
  1056. CTools™ does not (yet) add the parens for non-toolbox functions
  1057. which have no arguments.  I know.  I hate that, too.  But I have
  1058. macros for both " ()" and "();"  and they are easy to find and
  1059. add.
  1060.  
  1061. The fastest way to do these is let them all go as long as the
  1062. compiler does not complain.  Then, once you get to the end of the
  1063. file without syntax errors, use the CMaster™ prototype generator
  1064. to generate prototypes for the whole file and place them just
  1065. before the first routine.  Then, scroll down the prototype list
  1066. and find any void of arguments, select the routine name, use the
  1067. CMaster™ selection search arrow to find each occurrence of it. 
  1068. When you find one, simply hit the right arrow and then hit
  1069. ctrl-[1] or ctrl-option[1] as needed.  With "wrap" set on the
  1070. selection search, it will come back to the prototype and you’ll
  1071. know you got them all.  Then just do the next one down the list.
  1072.  
  1073. CTools™ also does not fix the parenthesis around casts.  If the
  1074. line says:
  1075.  
  1076. DoSomethingWith (char(doHickey));
  1077.  
  1078. Then you Find "(char(" and Replace All with "((char)(" and remove
  1079. the other paren’s around "(doHickey)" later, unless don’t you
  1080. *love* editing code!  They won’t hurt anything if left in.
  1081.  
  1082. The few remaining "gotchas" are regular C - plus toolbox -
  1083. compiler errors.  
  1084.  
  1085.  
  1086. Missing Ampersands
  1087. ------------------
  1088. Like "(FindWindow (), whichWindow);" having no ampersand (&)
  1089. before "whichWindow".  That one will cause a crash - not just a
  1090. debugger error, when you get past compile and link.
  1091.  
  1092. Speaking of ampersands... Toolbox calls requiring the "address of"
  1093. operator (ampersand, or ‘&’), like SetRect and lots of other
  1094. QuickDraw calls, are best handled (as I’ve said) for the whole
  1095. file when the first one is encountered.  CTools™ only takes care
  1096. of converting the ‘@’ which was already in the Pascal program. 
  1097. Almost ALL Pascal I’ve seen has no spaces before the first paren
  1098. of a call.  This is to your advantage in the translation process. 
  1099. Suppose you’re doing "SetRect" missing ampersands...
  1100.  
  1101. You want "Whole Words" checked so you don’t mess up "OffsetRect". 
  1102. But you also want "Ignore Case" checked in case there are
  1103. instances or "setrect" or "SETrect" or some such.  Fix all that
  1104. can be fixed with each correction you do.
  1105.  
  1106. Find "SetRect(" and replace with "SetRect (&".  See?  We added a
  1107. space before the paren.  Why?  Well, if you do Replace All, it
  1108. won’t matter.  But if you replace one at a time (Replace, Find
  1109. Again) you have to be careful not to go past where you started,
  1110. thus creating more editing to handle the over correction.  It will
  1111. find "SetRect(&" and fix it with "SetRect(&&".  See?  With the
  1112. space after the paren it won’t redo one already done.
  1113.  
  1114. So I always add the space between the call and its paren,
  1115. especially when using Command G/H.  Besides, it’s proper
  1116. punctuation in English!
  1117.  
  1118. (The "CopyBits" and "CopyMask" will drive you crazy if you
  1119. translate Stella Obscura by John Calhoun!  CopyBits needs 4
  1120. ampersands.  As I recall, there were 90 CopyBits calls in Stella
  1121. Obscura - probably 45 CopyMask calls!  I can probably set up some
  1122. built in macros to handle some of these.)
  1123.  
  1124. In my KodeKeys macros, I use the single ‘.’ key on the numeric
  1125. keypad section of the keyboard to type an ampersand.  That way I
  1126. don’t have to use the shift key.  One hand on the mouse and one
  1127. finger on the other hand on that key and I can knock these things
  1128. in like nobody’s business.
  1129.  
  1130.  
  1131. Array Elements
  1132. --------------
  1133. Since Pascal counts from ‘1’ and C counts from ‘0’ you’ll have to
  1134. manually adjust array element designations.
  1135.  
  1136. In Pascal:
  1137.  
  1138.     procedure Normalize (var ThePoint: Coordinates);
  1139.         var
  1140.             Length: Real;
  1141.     begin
  1142.         Length := SQRT(ThePoint[1] * ThePoint[1] + 
  1143.                        ThePoint[2] * ThePoint[2] + 
  1144.                        ThePoint[3] * ThePoint[3]);
  1145.  
  1146.         ThePoint[1] := ThePoint[1] / Length;
  1147.         ThePoint[2] := ThePoint[2] / Length;
  1148.         ThePoint[3] := ThePoint[3] / Length
  1149.     end;
  1150.  
  1151. shows the array "ThePoint" to have 3 elements.  It’s still 3 in C 
  1152. but are designated 0, 1 and 2 instead of 1, 2 and 3.  So the above
  1153. would become:
  1154.  
  1155. void Normalize (Coordinates *ThePoint);
  1156. {
  1157.     double Length;
  1158.  
  1159.     Length = sqrt(ThePoint[0] * ThePoint[0] + 
  1160.                   ThePoint[1] * ThePoint[2] + 
  1161.                   ThePoint[2] * ThePoint[2]);
  1162.                   ThePoint[0] = ThePoint[0] / Length;
  1163.                   ThePoint[1] = ThePoint[1] / Length;
  1164.                   ThePoint[2] = ThePoint[2] / Length
  1165. }
  1166.  
  1167. All array element designations reduced by one.  There ARE some
  1168. that don’t get changed.  You’ll have to play it by ear to see
  1169. which is which.  The key is in the declaration.  If it says
  1170. "typedef short widget [3]" then you know that "widget[1]" is one
  1171. too high.  This is probably why the original author added the "+1"
  1172. the the array bounds parser - so this would still work (?). 
  1173.  
  1174. While we’re on arrays, CTools™ doesn’t bracket two dimensional
  1175. ones right.  If the Pascal says "widgets [1, 20]" then  will, too.
  1176.  So you have to replace the ", " with "][" between them, to make
  1177. "widgets[1][20]".  The compiler will find these for you.  If you
  1178. have a lot of them, you may be able to Find all "[1, " and replace
  1179. with "[1][" to do it faster.
  1180.  
  1181.  
  1182. Linking
  1183. -------
  1184. If you get a complete compile, chances are you’ll get some link
  1185. errors.  Usually, again, these will be because of screwed up
  1186. character case.  Some managed to sneak through.
  1187.  
  1188. With your C conversion is in one file, just Select All in the Link
  1189. Error window, copy and close it.  Then paste this stuff at the
  1190. bottom of the converted program file.  Now you can use my
  1191. Selection/Replace All macro to fix any of these stragglers (or use
  1192. your editors Find/Replace).  Then cut the errors back off the EOF
  1193. and try to get a run.  ALWAYS use debugger in the first run
  1194. attempts of a conversion!  It may run fine.  It may not.  If it
  1195. does not, the debugger MAY be a cushion against a crash or freeze.
  1196.  
  1197. I usually set a breakpoint after the first call in "main" and see
  1198. if it gets that far.  Then I "leapfrog" the rest of the way, in
  1199. the same way, finally tracking down any crashes, bugs, bus errors,
  1200. odd addresses - the usual.
  1201.  
  1202.  
  1203. Re-Splitting files:
  1204. -------------------
  1205. This is easy.  Hopefully, you have all the rough translated,
  1206. separate, unedited files added to your project file already, with
  1207. appropriate libraries added, and ready to "run."
  1208.  
  1209. With the Merge.c file open, get to the top of the file.  Once
  1210. there, read the file name that the first section goes to (if the
  1211. Pascal programmer didn’t put it there CTools™ did).  Remember that
  1212. fileName so you know where it goes.
  1213.  
  1214. Now, using the word "translation" as the search string, find the
  1215. next occurrence of that word.  It will be at the start of the
  1216. second file block of Merge.c.
  1217.  
  1218. Put the insertion point at the start of the line that
  1219. "translation" appears in, by clicking there.
  1220.  
  1221. Now, without clicking in the viewRect, use the vertical scroll
  1222. thumb and scroll back to the top of the file.
  1223.  
  1224. Hold down the shift key and click just before the start of any
  1225. text,  Hit Command C to cut that file off the top of the Merge.c 
  1226. file.  Be sure to Save the Merge.C file to manage memory as needed.
  1227.  
  1228. Now, open the file that cut source goes to and Select All and
  1229. paste.  You now have a brand new, shiny, C source file, in your
  1230. newly ported version of the Pascal project!  BEFORE you save the
  1231. file, use *Save As* from the File menu and remove the ".p" from
  1232. the file name.  This will make the name added to the project be
  1233. what it’s supposed to be and save the new file in the creator of
  1234. YOUR editor, rather than that of CTools™, as I mentioned earlier.
  1235.  
  1236. Continue these steps until the Merge.C file is empty.
  1237.  
  1238. At this point, run the CTools™ Source Code Formatter on each of
  1239. these files, if needed.
  1240.  
  1241.  
  1242. Done Deal!
  1243. ----------
  1244. Pat yourself on the back - but not to the point of getting
  1245. callouses!  You’ve just accomplished a major feat!  You’re a
  1246. "cunning linguist - you spoke Pascal AND C!"  But this may be
  1247. premature exhilaration - you still have to get the thing to run
  1248. right.  That’s not part of the job of CTools™.  That’s YOUR job. 
  1249. But the worst is over and you are unscathed and minus a few pots
  1250. of coffee (and maybe a box of Preparation H?).  Well done!
  1251.  
  1252.  
  1253. Extra Help
  1254. ----------
  1255. The best "text" on Pascal to C is a set of sources for the same
  1256. program in both languages and compared.  Aside from that, any
  1257. comparison of parts of a program (like a CopyBits call, for
  1258. example) is good.  A recent c.s.m.p. article on Pascal to C
  1259. reprinted from MacTech magazine was *excellent*!
  1260.  
  1261. Hope
  1262. ----
  1263. CTools™ will eventually be working a LOT better than it is.  It
  1264. already works a lot better than it once did.  CTools™ is basically
  1265. a text manipulating function set.  It doesn’t "know" Pascal OR C. 
  1266. As a "character pusher" it works pretty good.  But it doesn’t work
  1267. good enough to suit me.  Probably has a few "things to be desired"
  1268. for you, too.  Let me know what they are!
  1269.  
  1270. Considering a good Pascal to C converter can cost up to $7,500
  1271. (Sierra Software Innovations’ "p2c" MPW tool), CTools™ is a hell
  1272. of a deal!
  1273.  
  1274. Any questions?
  1275.  
  1276. Enjoy!
  1277.  
  1278. kenlong@netcom.com
  1279.  
  1280. Appendix
  1281.  
  1282. (Some of these are cosmetic.  Most are for character case.  Some
  1283. are for translation purposes.)
  1284.  
  1285. Color code: CTools™ 2.16, CTools™ 2.2
  1286.  
  1287. "and",    "&&"
  1288. "autokey",    "autoKey"
  1289. "backcolor",    "BackColor"
  1290. "begin",    "{"
  1291. "beginupdate",    "BeginUpdate"
  1292. "bitand",    ""
  1293. "bitmap",    "BitMap"
  1294. "bittst",    ""
  1295. "boolean",    "boolean"
  1296. "boolean",    "Boolean"
  1297. "bottom",    "bottom"
  1298. "bsl",    "//• <<"
  1299. "bsr",    "//• >>"
  1300. "button",    "Button ()"
  1301. "byte",    "char"
  1302. "case",    "switch"
  1303. "case",    "switch ("
  1304. "cgrafptr",    "CGrafPtr"
  1305. "char",    "char"
  1306. "charcodemask",    "charCodeMask"
  1307. "chr",    "char"
  1308. "closepoly",    "ClosePoly ()"
  1309. "closergn",    "CloseRgn "
  1310. "cmdkey",    "cmdKey"
  1311. "concat",    "strcat"
  1312. "const",    "/* CONST */\r#define "
  1313. "const",    "//• Constants:\r"
  1314. "controlhandle",    "ControlHandle"
  1315. "copy",    "strcpy"
  1316. "cos",    "cos"
  1317. "curresfile",    "CurResFile ()"
  1318. "dialogptr",    "DialogPtr"
  1319. "diskevt",    "diskEvt"
  1320. "div",    "/"
  1321. "do",    ")"
  1322. "downto",    ";/*DOWNTO*/"
  1323. "downto",    "; • >="
  1324. "drawmenubar",    "DrawMenuBar ()"
  1325. "else",    "; else"
  1326. "else",    "else"
  1327. "end",    "}"
  1328. "endupdate",    "EndUpdate"
  1329. "everyevent",    "everyEvent"
  1330. "extended",    "float"
  1331. "false",    "FALSE"
  1332. "false",    "false"
  1333. "fixed",    "Fixed"
  1334. "fontinfo",    "FontInfo"
  1335. "for",    "for ("
  1336. "forecolor",    "ForeColor"
  1337. "frontwindow",    "FrontWindow ()"
  1338. "getctseed",    "GetCTSeed ()"
  1339. "getdevicelist",    "GetDeviceList ()"
  1340. "getgdevice",    "GetGDevice ()"
  1341. "getmaindevice",    "GetMainDevice ()"
  1342. "getport",    "GetPort"
  1343. "grafptr",    "GrafPtr"
  1344. "handle",    "Handle"
  1345. "hidecursor",    "HideCursor ()"
  1346. "hidepen",    "HidePen ()"
  1347. "hlock",    "HLock"
  1348. "hunlock",    "HUnlock"
  1349. "if",    "if ("
  1350. "implementation",    "/* private (static) section */"
  1351. "implementation",    ""
  1352. "incontent",    "inContent"
  1353. "indesk",    "inDesk"
  1354. "indrag",    "inDrag"
  1355. "ingoaway",    "inGoAway"
  1356. "ingrow",    "inGrow"
  1357. "initcursor",    "InitCursor ()"
  1358. "initdialogs",    "InitDialogs"
  1359. "initfonts",    "InitFonts ()"
  1360. "initgraf",    "InitGraf"
  1361. "initmenus",    "InitMenus ()"
  1362. "initwindows",    "InitWindows ()"
  1363. "inline",    "\tasm\r\t{\r\t"
  1364. "inmenubar",    "inMenuBar"
  1365. "input",    "stdin"
  1366. "insetrect",    "InsetRect"
  1367. "insyswindow",    "inSysWindow"
  1368. "integer",    "int"
  1369. "integer",    "short"
  1370. "interface",    "/* exported symbol section */"
  1371. "interface",    "//• Proto's:"
  1372. "invertroundrect","InvertRoundRect"
  1373. "inzoomin",    "inZoomIn"
  1374. "inzoomout",    "inZoomOut"
  1375. "ioresult",    "errno"
  1376. "itemhit",    "itemHit"
  1377. "keydown",    "keyDown"
  1378. "left",    "left"
  1379. "length",    "strlen"
  1380. "line",    "Line"
  1381. "lineto",    "LineTo"
  1382. "longint",    "long"
  1383. "maxapplzone",    "MaxApplZone ()"
  1384. "memerror",    "MemError ()"
  1385. "mod",    "%"
  1386. "moremasters",    "MoreMasters ()"
  1387. "mousedown",    "mouseDown"
  1388. "moveto",    "MoveTo"
  1389. "newPixpat",    "NewPixPat ()"
  1390. "newpixmap",    "NewPixMap ()"
  1391. "newrgn",    "NewRgn ()"
  1392. "nil",    "NULL"
  1393. "not",    "!"
  1394. "null",    "NULL"
  1395. "obscurecursor"    ,"ObscureCursor ()"
  1396. "of",    "{"
  1397. "of",    ")\r\t\t\t{"
  1398. "offsetrect",    "OffsetRect"
  1399. "openpoly",    "OpenPoly ()"
  1400. "openrgn",    "OpenRgn ()"
  1401. "or",    "||"
  1402. "oserr",    "OSErr"
  1403. "otherwise",    "default"
  1404. "output",    "stdout"
  1405. "packed",    "/* PACKED */"
  1406. "packed",    "//• packed"
  1407. "pattern",    "Pattern"
  1408. "pennormal",    "PenNormal ()"
  1409. "pichandle",    "PicHandle"
  1410. "point",    "Point"
  1411. "pointer",    "Ptr"
  1412. "portbits",    "portBits"
  1413. "portrect",    "portRect"
  1414. "procedure",    "void"
  1415. "program",    "main"
  1416. "program",    "//• main"
  1417. "ptinrect",    "PtInRect"
  1418. "ptr",    "Ptr"
  1419. "qderror",    "QDError ()"
  1420. "random",    "Random ()"
  1421. "read",    "scanf"
  1422. "readln",    "/*LINE*/scanf"
  1423. "readln",    "//• scanf"
  1424. "real",    "double"
  1425. "record",    ""
  1426. "rect",    "Rect"
  1427. "repeat",    "do {"
  1428. "repeat",    "do\r\t\t{"
  1429. "reserror",    "ResError ()"
  1430. "rgbcolor",    "RGBColor"
  1431. "rgnhandle",    "RgnHandle"
  1432. "right",    "right"
  1433. "round",    "ceil"
  1434. "screenbits",    "screenBits"
  1435. "setport",    "SetPort"
  1436. "setrect",    "SetRect"
  1437. "showcursor",    "ShowCursor ()"
  1438. "showpen",    "ShowPen ()"
  1439. "showwindow",    "ShowWindow"
  1440. "sin",    "sin"
  1441. "size",    "Size"
  1442. "sizeof",    "sizeof"
  1443. "sqrt",    "sqrt"
  1444. "srcxor",    "srcXor"
  1445. "str255",    "Str255"
  1446. "sysbeep",    "SysBeep"
  1447. "sysenvrec",    "SysEnvRec"
  1448. "systemtask",    "SystemTask ()"
  1449. "teinit",    "TEInit ()"
  1450. "the",    "the"
  1451. "then",    ")"
  1452. "theport",    "qd.thePort"
  1453. "tickcount",    "TickCount ()"
  1454. "to",    ";"
  1455. "to",    "; • <"
  1456. "top",    "top"
  1457. "true",    "TRUE"
  1458. "true",    "true"
  1459. "trunc",    "floor"
  1460. "type",    "\r/* typedefs */\r"
  1461. "type",    "//• typedefs:"
  1462. "udateevt",    "updateEvt"
  1463. "unit",    "//•"
  1464. "unloadscrap",    "UnloadScrap ()"
  1465. "until",    "} until ("
  1466. "until",    "} while (! "
  1467. "updateevt",    "updateEvt"
  1468. "uses",    "\r/* USES */\r#include"
  1469. "uses",    "//• includes:"
  1470. "var",    "\r/* VAR */\r"
  1471. "var",    ""
  1472. "whichwindow",    "whichWindow"
  1473. "while",    "while ("
  1474. "windowptr",    "WindowPtr"
  1475. "with",    "/* WITH */"
  1476. "with",    "//• WITH: "
  1477. "write",    "printf"
  1478. "writeln",    "/*LINE*/printf"
  1479. "writeln",    "//• printf"
  1480. "zeroscrap",    "ZeroScrap ()"
  1481.